# 分阶段构建
FROM registry.phbs-ai.perfectcode.tech/cedb/aida2-qa-builder:lts as build

# 拷贝源码
COPY . /home/app

ENV PATH="/home/node_modules/.bin:${PATH}"

# 编译项目, yarn需要加 --modules-folder 参数
RUN cd /home/app && \
    # ln -s /home/node_modules node_modules && \
    # mv /home/node_modules node_modules && \
    # yarn install --offline && \
    # yarn --modules-folder=/home/node_modules install && \
    echo "# Start Build..." && yarn --modules-folder=/home/node_modules build

FROM alpine

# 最后镜像只保留编译后到代码到 /home/src 目录
COPY --from=build /home/app/build /home/src
COPY ./docker/shell /home/shell

RUN chmod +x /home/shell/*.sh

ENV PATH="/home/shell:${PATH}"

WORKDIR /home/src

# Usage: volume external dir to /link-src
CMD cp_r.sh /home/src /link-src
